﻿using System.Security.Claims;
using log4net;
using Mathmall.Administration.common;
using Mathmall.Administration.Models;
using Mathmall.Administration.Service;
using Mathmall.Administration.Vo;
using Microsoft.AspNetCore.Mvc;
using System.Text.Json;
using Mathmall.Administration.Mapper;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Identity;

namespace Mathmall.Administration.Controllers
{
    [Route("/api/[controller]")]
    [ApiController]
    public class LoginController : ControllerBase
    {
        private static readonly ILog _logger = LogManager.GetLogger(typeof(LoginController));

        private readonly IUserService _userService;
        private readonly UserMapper _userMapper;

        public LoginController(IUserService userService, UserMapper userMapper)
        {
            _userService = userService;
            _userMapper = userMapper;
        }

        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="loginVo"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult<UserVo>> Login(LoginVo loginVo)
        {
            UserVo userVo = await _userService.UserLogin(loginVo);

            if (userVo is not null)
            {
                return userVo;
            }

            return NotFound();
        }
    }
}